var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http){
	$scope.reminder = false;             //提示框
	$scope.close = function(){
		history.go(-1)
	}
	
	$scope.show = true;
    $http({
	    method : "post",
	    dataType: "json",
		withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
		crossDomain: true,
		headers:{'Content-Type': 'application/x-www-form-urlencoded'},
	    async:true,
	    url : host + "/terminal/shipping/getDefault"
	}).success(function(response){
		console.log(response);
		if(!response.data.shipping){
			$scope.show = false;
		}
	    if(response.code == 2000){
	        $scope.arr0 = response.data.shipping;
	    }
	})
	
	$http({
	    method : "post",
	    dataType: "json",
		withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
		crossDomain: true,
		headers:{'Content-Type': 'application/x-www-form-urlencoded'},
	    async:true,
	    url : host + "/terminal/shipping/list"
	}).success(function(response){
	    if(response.code == 2000){
	        $scope.arr1 = response.data.shippings;
	        $scope.num = response.data.shippings.length;
	    }
	    if(response.code == 4003){
	    	$scope.reminder = true; 
			$scope.message = response.message;
	    }
	})
	
	$scope.toAdd = function(){
		window.location.href="addAddress.html"
	}
	
	$scope.remove = function(x){
		var params = {
			code :  x
		};
		params = $.param(params);
		$http({
		    method : "post",
		    dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
			crossDomain: true,
			headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		    async:true,
		    data : params,
		    url : host + "/terminal/shipping/delete"
		}).success(function(response){
			location.reload();
		})
	}
	
	$scope.setMainAddress = function(x){
		var params = {
			code :  x
		};
		params = $.param(params);
		$http({
		    method : "post",
		    dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
			crossDomain: true,
			headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		    async:true,
		    data : params,
		    url : host + "/terminal/shipping/setDefault"
		}).success(function(response){
			location.reload();
		})
	}
	
	$scope.editorAddress = function(x){
		window.location.href = "changeAddress.html?code=" + x;
	}
	
})
